var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/help/EnterprisePositionsHelp.tsx
var EnterprisePositionsHelp_exports = {};
__export(EnterprisePositionsHelp_exports, {
  EnterprisePositionsHelp: () => EnterprisePositionsHelp
});
module.exports = __toCommonJS(EnterprisePositionsHelp_exports);
var import_react = __toESM(require("react"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_org_tree = require("../org-tree");
var import_common = require("./common");
function OrgTree(props) {
  const params = (0, import_react.useMemo)(() => {
    return { containDept: false, dataAccessAuth: true, ...props.params };
  }, [props.params]);
  return /* @__PURE__ */ import_react.default.createElement(import_org_tree.OrgTree, { defaultSelectedFirstNode: true, ...props, params });
}
var { Option } = import_functionalComponent.Tabs;
var { Header, Footer, MultipleButtons } = import_functionalComponent.BaseHelp;
var tableProps = {
  rowSelected: false,
  rowChecked: true,
  cache: false,
  headerMenu: false,
  style: { borderStyle: "solid", borderColor: "var(--border-color-split, #f0f0f0)", borderWidth: 1 }
};
function HelpContent() {
  const {
    request,
    ok,
    contentParams: { getFieldValue, columns, helpTitle, helpId, selectedArray, multiple, footer, treeProps },
    locale,
    randomKey
  } = (0, import_react.useContext)(import_functionalComponent.HelpContext);
  const btnRef = (0, import_react.useRef)();
  const [activeKey, setActiveKey] = (0, import_react.useState)("0");
  const [treeSelectedKeys, setTreeSelectedKeys] = (0, import_react.useState)([]);
  const rightTable = (0, import_react.useRef)();
  const getTable = () => import_util.iup.compIns[`${helpId}_${randomKey}_${activeKey}`].getApi();
  const getResult = () => {
    if (multiple) {
      const result = rightTable.current.getApi().getRows().map((r) => ({
        value: getFieldValue(r),
        label: getFieldValue(r, "label"),
        origin: { ...r }
      }));
      return result.length > 0 ? result : void 0;
    } else {
      const value = getTable().getSelectedData()[0];
      if (value) {
        return { value: getFieldValue(value), label: getFieldValue(value, "label"), origin: { ...value } };
      }
      return void 0;
    }
  };
  const toRight = (values) => {
    if (multiple) {
      btnRef.current.toRight(values);
    } else {
      ok(getResult());
    }
  };
  const onSearch = (value) => {
    if (activeKey === "0") {
      getTable().query({ keyword: value });
    } else {
      getTable().filter(value);
    }
  };
  const onSelectCallback = (0, import_util.useRefCallback)((keys, nodes) => {
    getTable().setExtraParam({ treeNodes: nodes });
  });
  const onControlledSelect = (0, import_util.useRefCallback)((keys, { selectedNodes }) => {
    const treeNodes = selectedNodes.filter((xt) => !treeSelectedKeys.includes(xt.key)) || [];
    const treeKeys = keys.filter((xt) => !treeSelectedKeys.includes(xt)) || [];
    setTreeSelectedKeys(treeKeys);
    getTable().setExtraParam({ treeNodes });
  });
  const tabTitle = (t) => /* @__PURE__ */ import_react.default.createElement("span", { style: { padding: "0 8px" } }, t);
  const tabBarExtraContent = /* @__PURE__ */ import_react.default.createElement(import_baseComponent.Search, { size: "small", allowClear: true, placeholder: locale.searchPlaceholder, onSearch });
  tableProps.checkbox = multiple ? "checked" : false;
  tableProps.rowSelected = !multiple;
  tableProps.rowChecked = multiple;
  const renderTable = (index) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        ...tableProps,
        style: { ...tableProps.style, borderTopWidth: 0 },
        id: `${helpId}_${randomKey}_${index}`,
        columns,
        pagination: {
          height: 32,
          showQuickJumper: false,
          align: "left",
          targetContainer: multiple && index === 0 ? `${helpId}_${randomKey}_pagination` : ""
        },
        onRow: (rowIndex, table) => ({
          onDoubleClick: () => toRight([table.getRow(rowIndex)])
        }),
        autoLoad: treeProps.defaultSelectedFirstNode === false,
        request,
        response: (res) => ({ total: res.total ?? 0, record: res.list || [] })
      }
    );
  };
  const borderStyle = activeKey === "0" ? "1px solid var(--border-color-split, #f0f0f0)" : "1px solid transparent";
  return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, null, /* @__PURE__ */ import_react.default.createElement(Header, { title: helpTitle || "企业岗位帮助" }), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { direction: "row", style: { padding: "0 5px", borderBottom: multiple ? borderStyle : 0 } }, /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { flex: 2 }, /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Tabs, { className: "fit-height", size: "small", onChange: setActiveKey, tabBarExtraContent }, /* @__PURE__ */ import_react.default.createElement(Option, { tab: tabTitle(locale.List), key: "0" }, /* @__PURE__ */ import_react.default.createElement(import_util.Layout, { direction: "row", style: { height: "100%" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 200, borderLeft: borderStyle, borderBottom: multiple ? 0 : borderStyle } }, /* @__PURE__ */ import_react.default.createElement(
    OrgTree,
    {
      ...treeProps,
      onSelect: onControlledSelect,
      selectedKeys: treeSelectedKeys,
      convertNode: (node, levelIndex) => {
        if (levelIndex.level === 0 && levelIndex.index === 0) {
          onControlledSelect([node.key], { selectedNodes: [node] });
        }
        return node;
      },
      titleRender: ({ title, key }) => /* @__PURE__ */ import_react.default.createElement(
        import_functionalComponent.Dropdown,
        {
          disabled: !treeSelectedKeys.includes(key),
          trigger: ["contextMenu"],
          menu: { items: [{ key: "cancle", label: "取消选中" }] },
          placement: "top"
        },
        /* @__PURE__ */ import_react.default.createElement("span", null, title)
      )
    }
  )), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { style: { paddingBottom: multiple ? 32 : 0 } }, renderTable(0)))))), multiple && /* @__PURE__ */ import_react.default.createElement(
    MultipleButtons,
    {
      getRowKey: getFieldValue,
      outRef: btnRef,
      getActiveTable: getTable,
      getResultTable: () => rightTable.current.getApi()
    }
  ), multiple && /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, { style: { paddingTop: 7, paddingBottom: activeKey === "0" ? 32 : 0 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      columns,
      dataSource: selectedArray,
      ref: rightTable,
      onRow: (rowIndex) => ({
        onDoubleClick: () => btnRef.current.toLeft(rowIndex)
      })
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      id: `${helpId}_${randomKey}_pagination`,
      style: {
        position: "absolute",
        left: activeKey === "1" ? 14 : 205,
        right: 15,
        borderLeft: borderStyle,
        paddingLeft: 10
      }
    }
  ))), /* @__PURE__ */ import_react.default.createElement(Footer, { getResult }, footer && /* @__PURE__ */ import_react.default.createElement("span", { style: { flex: 1, width: 0 }, children: footer })));
}
var EnterprisePositionsHelp = (0, import_util.compHoc)((props) => {
  const cacheHelpInfo = (0, import_react.useRef)({ data: null, p: null });
  const {
    valueField = "postNo",
    labelField = "postName",
    displayField,
    userCodeField,
    title,
    multiple = false,
    modalProps,
    footer,
    params: treeParams,
    treeRequest,
    beforeRequest: beforeTreeRequest,
    enterprisePositionsRequest,
    enterprisePositionsParams = {},
    columns,
    onBeforeOpen,
    treeProps,
    ...others
  } = props;
  const helpId = "enterprisePositions";
  const otherProps = others;
  otherProps.onBeforeOpen = (0, import_util.useRefCallback)(async () => {
    const [status, helpInfo] = await (0, import_common.getHelpBeforeOpen)({ onBeforeOpen, cacheHelpInfo });
    if (import_util.iup.isObject(helpInfo)) {
      return helpInfo;
    }
    return status;
  });
  otherProps.request = (0, import_util.useRefCallback)(async ({ pageIndex, pageSize, keyword = "", treeNodes }) => {
    var _a, _b;
    const data = {
      ...enterprisePositionsParams,
      pageNum: pageIndex,
      pageSize,
      keyWord: keyword.trim(),
      orgNo: ((_a = treeNodes == null ? void 0 : treeNodes[0]) == null ? void 0 : _a.code) || ((_b = treeProps == null ? void 0 : treeProps.params) == null ? void 0 : _b.code)
    };
    if (enterprisePositionsRequest) {
      return await enterprisePositionsRequest(data);
    }
    const res = await import_util.iup.request.get({
      url: "/basedata/post/queryEntPostListByOrgNo",
      data
    });
    if ((res == null ? void 0 : res.code) === 0)
      return res == null ? void 0 : res.data;
    return { list: [], total: 0 };
  });
  otherProps.valueField = valueField;
  otherProps.userCodeField = userCodeField;
  otherProps.labelField = labelField || displayField;
  otherProps.contentParams = {
    footer,
    helpId,
    multiple,
    valueField,
    labelField: otherProps.labelField,
    treeProps: {
      params: treeParams,
      beforeRequest: beforeTreeRequest,
      treeRequest,
      ...treeProps
    },
    columns: columns ?? [
      { dataIndex: "postNo", title: "岗位编码", width: multiple ? 150 : 180 },
      { dataIndex: "postName", title: "岗位名称", tooltip: true, width: 180 },
      { dataIndex: "orgName", title: "所属组织", tooltip: true, width: 180 },
      { dataIndex: "deptName", title: "所属部门", tooltip: true, width: 180 }
    ]
  };
  if (title) {
    otherProps.contentParams.helpTitle = title;
  }
  if (onBeforeOpen) {
    otherProps.cache = false;
  }
  otherProps.selectedRequest = (0, import_util.useRefCallback)(async ({ codes }) => {
    try {
      const { code, data } = await import_util.iup.request.body({
        url: "/basedata/post/getEntPostListByPostNos",
        skipError: true,
        data: codes.split(",")
      });
      return code === 0 ? data : [];
    } catch (e) {
    }
    return [];
  });
  const { height, width } = (0, import_util.getGlobalConfig)().default.helpConfig;
  return /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.BaseHelp,
    {
      ...otherProps,
      modal: true,
      helpContent: HelpContent,
      multiple,
      modalProps: { width, height, ...modalProps }
    }
  );
}, "EnterprisePositionsHelp");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  EnterprisePositionsHelp
});
